// Metgine/Core/Singleton.h
//
// Copyright 2011 Phillip Stephens
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// Linking this library statically or dynamically with other modules is
// making a combined work based on this library.  Thus, the terms and
// conditions of the GNU General Public License cover the whole
// combination.

#ifndef __LOG_H__
#define __LOG_H__

#include <iostream>
#include <stdarg.h>
#include <string>

#include <Metgine/Core/Singleton.h>
#include <Metgine/Core/TextWriter.h>

namespace Metgine
{

namespace Core
{

namespace LogType
{
    enum LogType
    {
        Message,
        Warning,
        Error
    };
}; // LogType


class METGINE_API Log : public Singleton<Log>
{
    friend class Singleton<Log>;
    public:
        void Open(const std::string& path="./Log.txt");
        void Close();

        void Write(LogType::LogType, const char* format, ...);
    protected:
    private:
        void Write(LogType::LogType type, const char* format, va_list args);
        Log();
        ~Log();

        static const int MAX_LINE_LENGTH = 1024;
        char             m_buffer[MAX_LINE_LENGTH];
        TextWriter       m_writer;
}; // Log

}; // Core
}; // Metgine
#endif // LOG_H
